<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title></title>
</head>

<body>
    <!-- 引入vue的js文件，放在文件的头部 -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>


    <div id="root">

        <!-- 遍历数组 -->
        <h2>遍历数组</h2>
        <ul>
            <!-- 遍历数据中是对象时候， :key 用 p.id -->
            <li v-for="(p, index) in persons" :key="p.id">
                {{index}} - {{p.id}} - {{p.name}}
            </li>
        </ul>

        <!-- 遍历对象 -->
        <h2>遍历对象</h2>
        <ul>
            <li v-for="(item, index) in car" :key="index">
                <!-- 注意 index 是字段属性，item 是值-->
                {{index}} - {{item}}
            </li>
        </ul>

        <!-- 遍历字符串 -->
        <h2>遍历字符串</h2>
        <ul>
            <li v-for="(item, index) in str" :key="index">
                {{index}} - {{item}}
            </li>
        </ul>

        <!-- 遍历指定次数 -->
        <h2>遍历指定次数</h2>
        <ul>
            <li v-for="(item, index) in 5" :key="index">
                {{index}} - {{item}}
            </li>
        </ul>

    </div>


</body>
<script type="text/javascript">

    const vm = new Vue({
        el: "#root",
        data: {
            persons: [
                { id: '001', name: '张三', age: 18 },
                { id: '002', name: '李四', age: 19 },
                { id: '003', name: '王五', age: 20 },
            ],
            car: {
                name: '奥迪A6L',
                price: '50w',
                color: '黑色',
            },
            str: 'hello',
        },

    })
</script>

</html>